package com.kingwood.algorithm.test;

import java.util.Arrays;
import java.util.Scanner;
/**
 * @Author 22025812
 * @Description: 开源项目热榜、开源项目热度榜单
 * @Date: 2024/2/27 8:58
 * @Modified By：
 * @Version 1.0
 */
public class OpenSourceProjectRank {

    static class Project {
        String name;
        int hot;
        public Project(String name, int hot) {
            this.name = name;
            this.hot = hot;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] weights = new int[5];
        for (int i = 0; i < 5; i++) {
            weights[i] = sc.nextInt();
        }

        Project[] projects = new Project[n];
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            int hot = 0;
            for (int j = 0; j < 5; j++) {
                hot += sc.nextInt() * weights[j];
            }
            projects[i] = new Project(name, hot);
        }

        Arrays.sort(
                projects,
                (a, b) ->
                        a.hot != b.hot ? b.hot - a.hot : a.name.toLowerCase().compareTo(b.name.toLowerCase()));

        for (Project project : projects) {
            System.out.println(project.name);
        }
    }
}
